/*
 * BoolSymbolNode.cpp
 *
 *  Created on: 28/dic/2010
 *      Author: computer
 */

#include "DerivationTree.h"
#include "CallInstruction.h"

BoolSymbolNode::BoolSymbolNode() : NodeTree_CRTP<BoolSymbolNode>(), buffer(0), length(0) { }

BoolSymbolNode::BoolSymbolNode(char* _buffer, unsigned int _length) : NodeTree_CRTP<BoolSymbolNode>(), buffer(_buffer), length(_length) { }

BoolSymbolNode::BoolSymbolNode(const BoolSymbolNode& copy) : NodeTree_CRTP<BoolSymbolNode>(copy) {
	length = copy.length;//TODO memory leak
	buffer = new char[length];
	for (unsigned int i = 0; i < length; ++i) buffer[i] = copy.buffer[i];
}

std::string BoolSymbolNode::getName() const {
	return std::string(buffer);
}

bool BoolSymbolNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	AutoPointer<TreeExpression::Expression> ris;
	if (this->getName() == "==") {
		LVM->push(AutoPointer<TreeExpression::Expression>(new TreeExpression::CallInstruction("operator==")));
	}
	else if (this->getName() == "!=") {
		LVM->push(AutoPointer<TreeExpression::Expression>(new TreeExpression::CallInstruction("operator!=")));
	}
	else if (this->getName() == ">") {
		LVM->push(AutoPointer<TreeExpression::Expression>(new TreeExpression::CallInstruction("operator>")));
	}
	else if (this->getName() == "<") {
		LVM->push(AutoPointer<TreeExpression::Expression>(new TreeExpression::CallInstruction("operator<")));
	}
	return true;
}
